package com.anolesoft.yr.mbus.contm.service.impl;

import cn.hutool.core.util.StrUtil;

import com.anolesoft.common.core.constant.Constants;
import com.anolesoft.common.core.web.domain.AjaxResult;
import com.anolesoft.common.core.web.page.TableDataInfo;
import com.anolesoft.yr.mbus.contm.entity.ContmStyleMainExample;
import com.anolesoft.yr.mbus.contm.service.ContmStyleMainService;
import com.anolesoft.yr.mbus.contm.dao.ContmStyleMainDao;
import com.anolesoft.yr.mbus.contm.entity.ContmStyleMain;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ContmStyleMainServiceImpl implements ContmStyleMainService {
    public ContmStyleMainServiceImpl(ContmStyleMainDao contmStyleMainDao) {
        this.contmStyleMainDao = contmStyleMainDao;
    }

    private ContmStyleMainDao contmStyleMainDao;
    @Override
    public AjaxResult get(ContmStyleMain contmStyleMain) {
        String styleName = StrUtil.nullToEmpty(contmStyleMain.getStyleName());
        LambdaQueryWrapper<ContmStyleMain> like = new QueryWrapper<ContmStyleMain>()
                .lambda()
                .like(ContmStyleMain::getStyleName, styleName)
                .eq(ContmStyleMain::getDelFlag, Constants.NOT_DEL_FLAG)
                .orderByDesc(ContmStyleMain::getCTime);

        Page <ContmStyleMain>page = new Page<>(contmStyleMain.getPage(), contmStyleMain.getRows());
        List<ContmStyleMain> contmStyleMains = contmStyleMainDao.selectAll(page, like);

        return  AjaxResult.success(new TableDataInfo(page.getTotal(), contmStyleMains));


    }
    @Override
    public AjaxResult del(String objuid) {
       contmStyleMainDao.deleteByPrimaryKey(objuid);
        return  AjaxResult.success("删除成功");

    }

    @Override
    public AjaxResult delBatch(List<ContmStyleMain> contmStyleMains){

        contmStyleMains.forEach(a->{
            contmStyleMainDao.deleteByPrimaryKey(a.getObjuid());

        });
        return  AjaxResult.success("删除成功");

    }
    @Override
    public AjaxResult add(ContmStyleMain contmStyleMain){
        contmStyleMainDao.insert(contmStyleMain);
        return  AjaxResult.success("保存成功");
    }

    @Override
    public AjaxResult getById(String objuid) {
        ContmStyleMain contmStyleMain = contmStyleMainDao.selectByPrimaryKey(objuid);
        return AjaxResult.success(contmStyleMain);
    }

    @Override
    public List<ContmStyleMain> selectList(){
        ContmStyleMainExample contmStyleMainExample = new ContmStyleMainExample();
        contmStyleMainExample.createCriteria().andDelFlagEqualTo(Byte.parseByte("0"));
        List<ContmStyleMain> contmStyleMains = contmStyleMainDao.selectByExample(contmStyleMainExample);
        return contmStyleMains;

    }
}
